<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2011, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */
// ------------------------------------------------------------------------

/**
 * Database Driver Class
 *
 * This is the platform-independent base DB implementation class.
 * This class will not be called directly. Rather, the adapter
 * class for the specific database will extend and instantiate it.
 *
 * @package		CodeIgniter
 * @subpackage	Drivers
 * @category	Database
 * @author		ExpressionEngine Dev Team
 * @link		http://codeigniter.com/user_guide/database/
 */
class MY_DB_driver extends CI_DB_driver {

    private $ci = null;

    /**
     * Constructor.  Accepts one parameter containing the database
     * connection settings.
     *
     * @param array
     */
    function __construct($params) {
        parent::__construct($params);
        log_message('debug', 'MY Database Driver Class Initialized');
    }

    // --------------------------------------------------------------------

    /**
     * Execute the query
     *
     * Accepts an SQL string as input and returns a result object upon
     * successful execution of a "read" type query.  Returns boolean TRUE
     * upon successful execution of a "write" type query. Returns boolean
     * FALSE upon failure, and if the $db_debug variable is set to TRUE
     * will raise an error.
     *
     * @access	public
     * @param	string	An SQL query string
     * @param	array	An array of binding data
     * @return	mixed
     */
    function query($sql, $binds = FALSE, $return_object = TRUE) {
        if (stristr($sql, 'INSERT INTO logs_query') === FALSE OR stristr($sql, 'INSERT INTO `logs_query`') === FALSE) {
            if (stristr($sql, 'INSERT') OR stristr($sql, 'UPDATE') OR stristr($sql, 'DELETE')) {
                $this->ci = &get_instance();
                if ($this->ci->session->userdata('user_id') != false) {
                    $query = 'INSERT INTO logs_query (`function`, `ip`, `users_id`, `query`) ' . "\n"
                            . ' VALUES ("' . $this->ci->uri->uri_string() . '", "' . $this->ci->input->ip_address() . '", ' . $this->ci->session->userdata('user_id') . ', "' . $sql . '");';
                    parent::query($query, FALSE, TRUE);
                }
            }
        }

        return parent::query($sql, $binds, $return_object);
    }

}

/* End of file MY_DB_driver.php */
/* Location: ./system/database/MY_DB_driver.php */
